﻿using FFIV.Lib.BusinessRules;
using FFIV.Lib.IView.Articles;
using FFIV.Lib.IView.Categories;
using FFIV.Lib.Model;
using FFIV.Lib.Utilities;

namespace FFIV.Lib.Controlers.Articles
{
	public class ListController
	{
		private readonly IDetailCategory m_CategoryView;
		private readonly IArticlesList m_ArticlesList;

		public ListController(IDetailCategory viewCategory, IArticlesList viewArticle)
		{
			m_CategoryView = viewCategory;
			m_ArticlesList = viewArticle;
		}

		public void LoadPage()
		{
			m_CategoryView.Categories = CategoriesUtility.GetCategories();
			int categoryId = ParamUtility.GetQueryStringValue("id", 1);
			m_ArticlesList.Articles = ArticlesRules.GetArticleByCategoryId(categoryId);
			m_ArticlesList.NextPageUrl = UrlUtility.GetCategoriesUrl(categoryId, m_ArticlesList.PageIndex + 1);
			m_ArticlesList.PreviousPageUrl = UrlUtility.GetCategoriesUrl(categoryId, m_ArticlesList.PageIndex - 1);
		}

		public HtmlHeaderInfo GetHtmlInfo()
		{
			string name = CategoriesUtility.GetCategoryNodeById(ParamUtility.GetQueryStringValue("id", 1)).Name;
			return new HtmlHeaderInfo(name, "放飞技术网文档中心，收集了来自放飞技术网成员和网络的数百篇技术文章。", "");
		}
	}
}
